home *** CD-ROM | disk | FTP | other *** search
/ Internet Surfer 2.0 / Internet Surfer 2.0 (Wayzata Technology) (1996).iso / pc / textfile / faqs / motf_faq / part3 < prev    next >
Encoding:
Text File  |  1992-12-26  |  43.5 KB  |  1,164 lines

  1. Xref: bloom-picayune.mit.edu comp.windows.x.motif:13659 news.answers:4510
  2. Newsgroups: comp.windows.x.motif,news.answers
  3. Path: bloom-picayune.mit.edu!enterpoop.mit.edu!news.media.mit.edu!micro-heart-of-gold.mit.edu!wupost!uunet!munnari.oz.au!manuel.anu.edu.au!csc.canberra.edu.au!news
  4. From: jan@ise.canberra.edu.au (Jan Newmarch)
  5. Subject: Motif FAQ (Part 3 of 5)
  6. Message-ID: <1992Dec10.001621.10506@csc.canberra.edu.au>
  7. Followup-To: comp.windows.x.motif
  8. Keywords: FAQ question answer
  9. Sender: news@csc.canberra.edu.au
  10. Reply-To: jan@ise.canberra.edu.au (Jan Newmarch)
  11. Organization: University of Canberra
  12. Date: Thu, 10 Dec 92 00:16:21 GMT
  13. Approved: news-answers-request@MIT.Edu
  14. Expires: +1 months
  15. Lines: 1147
  16.  
  17. Archive-name: motif-faq/part3
  18. Last-modified: Thu December 12 1992
  19. Version: 2.12
  20.  
  21.  
  22.  
  23. -----------------------------------------------------------------------------
  24. Subject: 57) TOPIC: FORM WIDGET
  25.  
  26.  
  27. -----------------------------------------------------------------------------
  28. Subject: 58) Why don't labels in a Form resize when the label is changed?
  29. I've got some labels in a form. The labels don't resize whenever the label
  30. string resource is changed. As a result, the operator has to resize the window
  31. to see the new label contents. I am using Motif 1.1.
  32.  
  33. Answer: This problem may happen to any widget inside a Form widget. The
  34. problem was that the Form will resize itself when it gets geometry requests
  35. from its children. If its preferred size is not allowed, the Form will
  36. disallow all geometry requests from its children. The workaround is that you
  37. should set any ancestor of the Form to be resizable. For the shell which
  38. contains the Form you should set the shell resource XmNallowShellResize to be
  39. True (by default, it is set to FALSE).  There is currently an inconsistency on
  40. how resizing is being done, and it may get fixed in Motif 1.2.
  41.  
  42. From db@sunbim.be (Danny Backx)
  43.  
  44. Basically what you have to do is set the XmNresizePolicy on the Form to
  45. XmRESIZE_NONE.  The facts seem to be that XmRESIZE_NONE does NOT mean "do not
  46. allow resizes".  You may also have to set XmNresizable on the form to True.
  47.  
  48. -----------------------------------------------------------------------------
  49. Subject: 59) How can I center a widget in a form?
  50.  
  51. Answer: One of Motif's trickier questions.  The problems are that: Form gives
  52. no support for centering, only for edge attachments, and the widget must stay
  53. in the center if the form or the widget is resized.  Just looking at
  54. horizontal centering (vertical is similar) some solutions are:
  55.  
  56.  a.  Use the table widget instead of Form.
  57.  
  58.  b.  A hack free solution is from Dan Heller:
  59.  
  60.      /* Written by Dan Heller.  Copyright 1991, O'Reilly && Associates.
  61.       * This program is freely distributable without licensing fees and
  62.       * is provided without guarantee or warranty expressed or implied.
  63.       * This program is -not- in the public domain.  This program is
  64.       * taken from the Motif Programming Manual, O'Reilly Volume 6.
  65.       */
  66.  
  67.      /* corners.c -- demonstrate widget layout management for a
  68.       * BulletinBoard widget.  There are four widgets each labeled
  69.       * top-left, top-right, bottom-left and bottom-right.  Their
  70.       * positions in the bulletin board correspond to their names.
  71.       * Only when the widget is resized does the geometry management
  72.       * kick in and position the children in their correct locations.
  73.       */
  74.      #include <Xm/BulletinB.h>
  75.      #include <Xm/PushBG.h>
  76.  
  77.      char *corners[] = {
  78.          "Top-Left", "Top-Right", "Bottom-Left", "Bottom-Right",
  79.      };
  80.  
  81.      static void resize();
  82.  
  83.      main(argc, argv)
  84.      int argc;
  85.      char *argv[];
  86.      {
  87.          Widget toplevel, bboard;
  88.          XtAppContext app;
  89.          XtActionsRec rec;
  90.          int i;
  91.  
  92.          /* Initialize toolkit and create toplevel shell */
  93.          toplevel = XtVaAppInitialize(&app, "Demos", NULL, 0,
  94.              &argc, argv, NULL, NULL);
  95.  
  96.          /* Create your standard BulletinBoard widget */
  97.          bboard = XtVaCreateManagedWidget("bboard",
  98.              xmBulletinBoardWidgetClass, toplevel, NULL);
  99.  
  100.          /* Set up a translation table that captures "Resize" events
  101.           * (also called ConfigureNotify or Configure events).  If the
  102.           * event is generated, call the function resize().
  103.           */
  104.          rec.string = "resize";
  105.          rec.proc = resize;
  106.          XtAppAddActions(app, &rec, 1);
  107.          XtOverrideTranslations(bboard,
  108.              XtParseTranslationTable("<Configure>: resize()"));
  109.  
  110.          /* Create children of the dialog -- a PushButton in each corner. */
  111.          for (i = 0; i < XtNumber(corners); i++)
  112.              XtVaCreateManagedWidget(corners[i],
  113.                  xmPushButtonGadgetClass, bboard, NULL);
  114.  
  115.          XtRealizeWidget(toplevel);
  116.          XtAppMainLoop(app);
  117.      }
  118.  
  119.      /* resize(), the routine that is automatically called by Xt upon the
  120.       * delivery of a Configure event.  This happens whenever the widget
  121.       * gets resized.
  122.       */
  123.      static void
  124.      resize(w, event, args, num_args)
  125.      CompositeWidget w;   /* The widget (BulletinBoard) that got resized */
  126.      XConfigureEvent *event;  /* The event struct associated with the event */
  127.      String args[]; /* unused */
  128.      int *num_args; /* unused */
  129.      {
  130.          WidgetList children;
  131.          int width = event->width;
  132.          int height = event->height;
  133.          Dimension w_width, w_height;
  134.          short margin_w, margin_h;
  135.  
  136.          /* get handle to BulletinBoard's children and marginal spacing */
  137.          XtVaGetValues(w,
  138.              XmNchildren, &children,
  139.              XmNmarginWidth, &margin_w,
  140.              XmNmarginHeight, &margin_h,
  141.              NULL);
  142.  
  143.          /* place the top left widget */
  144.          XtVaSetValues(children[0],
  145.              XmNx, margin_w,
  146.  
  147.              XmNy, margin_h,
  148.              NULL);
  149.  
  150.          /* top right */
  151.          XtVaGetValues(children[1], XmNwidth, &w_width, NULL);
  152.  
  153.          /* To Center a widget in the middle of the BulletinBoard (or Form),
  154.           * simply call:
  155.           *   XtVaSetValues(widget,
  156.                XmNx,    (width - w_width)/2,
  157.                XmNy,    (height - w_height)/2,
  158.                NULL);
  159.           * and return.
  160.           */
  161.          XtVaSetValues(children[1],
  162.              XmNx, width - margin_w - w_width,
  163.              XmNy, margin_h,
  164.              NULL);
  165.          /* bottom left */
  166.          XtVaGetValues(children[2], XmNheight, &w_height, NULL);
  167.          XtVaSetValues(children[2],
  168.  
  169.              XmNx, margin_w,
  170.              XmNy, height - margin_h - w_height,
  171.              NULL);
  172.          /* bottom right */
  173.          XtVaGetValues(children[3],
  174.              XmNheight, &w_height,
  175.              XmNwidth, &w_width,
  176.              NULL);
  177.          XtVaSetValues(children[3],
  178.              XmNx, width - margin_w - w_width,
  179.              XmNy, height - margin_h - w_height,
  180.              NULL);
  181.      }
  182.  
  183.  c.  No uil solution has been suggested, because of the widget size problem
  184.  
  185. -----------------------------------------------------------------------------
  186. Subject: 60) How do I line up two columns of widgets of different types?  I
  187. have a column of say label widgets, and a column of text widgets and I want to
  188. have them lined up horizontally. The problem is that they are of different
  189. heights. Just putting them in a form or rowcolumn doesn't line them up
  190. properly because the label and text widgets are of different height.
  191.  
  192. If you want the geometry to look like this
  193.  
  194.           -------------------------------------
  195.          |          -------------------------- |
  196.          |a label  |Some text                 ||
  197.          |          -------------------------- |
  198.                            ------------------- |
  199.          |a longer label  |Some more text     ||
  200.          |                 ------------------- |
  201.          |                    ---------------- |
  202.          |a very long label  |Even more text  ||
  203.          |                    ---------------- |
  204.           -------------------------------------
  205.  
  206. try
  207.  
  208. /* Written by Dan Heller.  Copyright 1991, O'Reilly && Associates.
  209.  * This program is freely distributable without licensing fees and
  210.  * is provided without guarantee or warranty expressed or implied.
  211.  * This program is -not- in the public domain.  This program is
  212.  * taken from the Motif Programming Manual, O'Reilly Volume 6.
  213.  */
  214.  
  215. /* text_form.c -- demonstrate how attachments work in Form widgets.
  216.  * by creating a text-entry form type application.
  217.  */
  218.  
  219. #include <Xm/PushB.h>
  220. #include <Xm/PushBG.h>
  221. #include <Xm/LabelG.h>
  222. #include <Xm/Text.h>
  223. #include <Xm/Form.h>
  224.  
  225. char *prompts[] = {
  226.     "Name:", "Phone:", "Address:",
  227.     "City:", "State:", "Zip:",
  228. };
  229.  
  230. main(argc, argv)
  231. int argc;
  232. char *argv[];
  233. {
  234.     Widget toplevel, mainform, subform, label, text;
  235.     XtAppContext app;
  236.     char buf[32];
  237.     int i;
  238.  
  239.     toplevel = XtVaAppInitialize(&app, "Demos", NULL, 0,
  240.         &argc, argv, NULL, NULL);
  241.  
  242.     mainform = XtVaCreateWidget("mainform",
  243.         xmFormWidgetClass, toplevel,
  244.         NULL);
  245.  
  246.     for (i = 0; i < XtNumber(prompts); i++) {
  247.         subform = XtVaCreateWidget("subform",
  248.             xmFormWidgetClass,   mainform,
  249.             /* first one should be attached for form */
  250.             XmNtopAttachment,    i? XmATTACH_WIDGET : XmATTACH_FORM,
  251.             /* others are attached to the previous subform */
  252.             XmNtopWidget,        subform,
  253.             XmNleftAttachment,   XmATTACH_FORM,
  254.             XmNrightAttachment,  XmATTACH_FORM,
  255.             NULL);
  256.         label = XtVaCreateManagedWidget(prompts[i],
  257.             xmLabelGadgetClass,  subform,
  258.             XmNtopAttachment,    XmATTACH_FORM,
  259.             XmNbottomAttachment, XmATTACH_FORM,
  260.             XmNleftAttachment,   XmATTACH_FORM,
  261.             XmNalignment,        XmALIGNMENT_BEGINNING,
  262.             NULL);
  263.         sprintf(buf, "text_%d", i);
  264.         text = XtVaCreateManagedWidget(buf,
  265.             xmTextWidgetClass,   subform,
  266.             XmNtopAttachment,    XmATTACH_FORM,
  267.             XmNbottomAttachment, XmATTACH_FORM,
  268.             XmNrightAttachment,  XmATTACH_FORM,
  269.             XmNleftAttachment,   XmATTACH_WIDGET,
  270.             XmNleftWidget,       label,
  271.             NULL);
  272.         XtManageChild(subform);
  273.     }
  274.     /* Now that all the forms are added, manage the main form */
  275.     XtManageChild(mainform);
  276.  
  277.     XtRealizeWidget(toplevel);
  278.     XtAppMainLoop(app);
  279. }
  280.  
  281. If you resize horizontally it stretches the text widgets.  If you resize
  282. vertically it leaves space under the bottom (if you don't resize, this is not
  283. problem).
  284.  
  285. If you want the text widgets to be lined up on the left, as in
  286.  
  287.           ----------------------------------------
  288.          |                    ------------------- |
  289.          |          a label  |Some text          ||
  290.          |                    ------------------- |
  291.                               ------------------- |
  292.          |   a longer label  |Some more text     ||
  293.          |                    ------------------- |
  294.          |                    ------------------- |
  295.          |a very long label  |Even more text     ||
  296.          |                    ------------------- |
  297.           ----------------------------------------
  298.  
  299. try this
  300.  
  301. /* Written by Dan Heller.  Copyright 1991, O'Reilly && Associates.
  302.  * This program is freely distributable without licensing fees and
  303.  * is provided without guarantee or warranty expressed or implied.
  304.  * This program is -not- in the public domain.  This program is
  305.  * taken from the Motif Programming Manual, O'Reilly Volume 6.
  306.  */
  307.  
  308. /* text_entry.c -- This demo shows how the RowColumn widget can be
  309.  * configured to build a text entry form.  It displays a table of
  310.  * right-justified Labels and Text widgets that extend to the right
  311.  * edge of the Form.
  312.  */
  313. #include <Xm/LabelG.h>
  314. #include <Xm/RowColumn.h>
  315. #include <Xm/Text.h>
  316.  
  317. char *text_labels[] = {
  318.     "Name:", "Phone:", "Address:", "City:", "State:", "Zip:",
  319. };
  320.  
  321. main(argc, argv)
  322. int argc;
  323. char *argv[];
  324. {
  325.     Widget toplevel, rowcol;
  326.     XtAppContext app;
  327.     char buf[8];
  328.     int i;
  329.  
  330.     toplevel = XtVaAppInitialize(&app, "Demos", NULL, 0,
  331.         &argc, argv, NULL, NULL);
  332.  
  333.     rowcol = XtVaCreateWidget("rowcolumn",
  334.         xmRowColumnWidgetClass, toplevel,
  335.         XmNpacking,        XmPACK_COLUMN,
  336.         XmNnumColumns,     XtNumber(text_labels),
  337.         XmNorientation,    XmHORIZONTAL,
  338.         XmNisAligned,      True,
  339.         XmNentryAlignment, XmALIGNMENT_END,
  340.         NULL);
  341.  
  342.     /* simply loop thru the strings creating a widget for each one */
  343.     for (i = 0; i < XtNumber(text_labels); i++) {
  344.         XtVaCreateManagedWidget(text_labels[i],
  345.             xmLabelGadgetClass, rowcol,
  346.             NULL);
  347.         sprintf(buf, "text_%d", i);
  348.         XtVaCreateManagedWidget(buf,
  349.             xmTextWidgetClass, rowcol,
  350.             NULL);
  351.     }
  352.  
  353.     XtManageChild(rowcol);
  354.     XtRealizeWidget(toplevel);
  355.     XtAppMainLoop(app);
  356. }
  357.  
  358. This makes all objects exactly the same size.  It does not resize in nice
  359. ways.
  360.  
  361. If you want the text widgets lined up on the left, and the labels to be the
  362. size of the longest string, resizing nicely both horizontally and vertically,
  363. as in
  364.  
  365.          -------------------------------------
  366.         |                    ---------------- |
  367.         |          a label  |Some text       ||
  368.         |                    ---------------- |
  369.                              ---------------- |
  370.         |   a longer label  |Some more text  ||
  371.         |                    ---------------- |
  372.         |                    ---------------- |
  373.         |a very long label  |Even more text  ||
  374.         |                    ---------------- |
  375.          -------------------------------------
  376.  
  377.  
  378.  
  379. Answer: Do this: to get the widgets lined up horizontally, use a form but
  380. place the widgets using XmATTACH_POSITION.  In the example, attach the top of
  381. the first label to the form, the bottomPosition to 33 (33% of the height).
  382. Attach the topPosition of the second label to 33 and the bottomPosition to 66.
  383. Attach the topPosition of the third label to 66 and the bottom of the label to
  384. the form.  Do the same with the text widgets.
  385.  
  386. To get the label widgets lined up vertically, use the right attachment of
  387. XmATTACH_OPPOSITE_WIDGET: starting from the one with the longest label, attach
  388. widgets on the right to each other. In the example, attach the 2nd label to
  389. the third, and the first to the second.  To get the text widgets lined up,
  390. just attach them on the left to the labels.  To get the text in the labels
  391. aligned correctly, use XmALIGNMENT_END for the XmNalignment resource.
  392.  
  393.         /* geometry for label 2
  394.         */
  395.         n = 0;
  396.         XtSetArg (args[n], XmNalignment, XmALIGNMENT_END); n++;
  397.         XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  398.         XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  399.         XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  400.         XtSetArg (args[n], XmNtopPosition, 66); n++;
  401.         XtSetValues (label[2], args, n);
  402.  
  403.         /* geometry for label 1
  404.         */
  405.         n = 0;
  406.         XtSetArg (args[n], XmNalignment, XmALIGNMENT_END); n++;
  407.         XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
  408.         XtSetArg (args[n], XmNbottomPosition, 66); n++;
  409.         XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  410.         XtSetArg (args[n], XmNtopPosition, 33); n++;
  411.         XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  412.         XtSetArg (args[n], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  413.         XtSetArg (args[n], XmNrightWidget, label[2]); n++;
  414.         XtSetValues (label[1], args, n);
  415.  
  416.         /* geometry for label 0
  417.         */
  418.         n = 0;
  419.         XtSetArg (args[n], XmNalignment, XmALIGNMENT_END); n++;
  420.         XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
  421.         XtSetArg (args[n], XmNbottomPosition, 33); n++;
  422.         XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  423.         XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  424.         XtSetArg (args[n], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  425.         XtSetArg (args[n], XmNrightWidget, label[1]); n++;
  426.         XtSetValues (label[0], args, n);
  427.  
  428.         /* geometry for text 0
  429.         */
  430.         n = 0;
  431.         XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  432.         XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
  433.         XtSetArg (args[n], XmNbottomPosition, 33); n++;
  434.         XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  435.         XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  436.         XtSetArg (args[n], XmNleftWidget, label[0]); n++;
  437.         XtSetValues (text[0], args, n);
  438.  
  439.         /* geometry for text 1
  440.         */
  441.         XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  442.         XtSetArg (args[n], XmNtopPosition, 33); n++;
  443.         XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
  444.         XtSetArg (args[n], XmNbottomPosition, 66); n++;
  445.         XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  446.         XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  447.         XtSetArg (args[n], XmNleftWidget, label[1]); n++;
  448.         XtSetValues (text[1], args, n);
  449.  
  450.         /* geometry for text 2
  451.         */
  452.         XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  453.         XtSetArg (args[n], XmNtopPosition, 66); n++;
  454.         XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  455.         XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  456.         XtSetArg (args[n], XmNleftWidget, label[2]); n++;
  457.         XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  458.         XtSetValues (text[2], args, n);
  459.  
  460.  
  461. -----------------------------------------------------------------------------
  462. Subject: 61) TOPIC: PUSHBUTTON WIDGET
  463.  
  464. -----------------------------------------------------------------------------
  465. Subject: 62) Why can't I use accelerators on buttons not in a menu?
  466.  
  467. Answer: It is apparently a difficult feature to implement, but OSF are
  468. considering this for the future. It is problematic trying to use the Xt
  469. accelerators since the Motif method interferes with this.  The workaround
  470. suggested so far is to duplicate your non-menu button by a button in a menu
  471. somewhere, which does have a menu-accelerator installed.  When the user
  472. invokes what they think is the accelerator for the button they can see Motif
  473. actually invokes the button on the menu that they can't see at the time.
  474.  
  475.  
  476. -----------------------------------------------------------------------------
  477. Subject: 63) TOPIC: LABEL WIDGET
  478.  
  479. -----------------------------------------------------------------------------
  480. Subject: 64) How can I align the text in a label (button, etc) widget?
  481.  
  482. Answer: The alignment for the label widget is controlled by the resource
  483. XmNalignment, and the default centers the text. Use this resource to change it
  484. to left or right alignment.  However, when the label (or any descendant) is in
  485. a row column, and XmNisAligned is True (the default), the row column aligns
  486. text using its resource XmNentryAlignment. If you want simultaneous control
  487. over all widgets use this, but otherwise turn XmNisAligned off and do it
  488. individually.
  489.  
  490.  
  491.  
  492. -----------------------------------------------------------------------------
  493. Subject: 65) Why doesn't label alignment work in a RowColumn?
  494.  
  495. Answer: RowColumn has a  resource XmNisAligned (default True) and and
  496. XmNentryAlignment (default XmALIGNMENT_BEGINNING).  These control alignment of
  497. the labelString in Labels and descendants. Set XmNisAligned to False to turn
  498. this off.
  499.  
  500. -----------------------------------------------------------------------------
  501. Subject: 66)  How can I set a multiline label?
  502. [Last modified: September 92]
  503.  
  504. Answer: In .Xdefaults
  505.  
  506.       *XmLabel*labelString:             Here\nis\nthe\nLabel
  507.  
  508. This method does not seem to work in some of the older Motif 1.0 versions.
  509.  
  510. In code,
  511.  
  512.       char buf[128];
  513.       XmString msg;
  514.       sprintf(buf, "Here\nis\nthe\nLabel");
  515.       msg = XmStringCreateLtoR(buf, XmSTRING_DEFAULT_CHARSET);
  516.       XtSetArg (args[n], XmNlabelString, msg);
  517.  
  518. Gives a four line label, using the escape sequence \n for a newline.  However,
  519. XmStringCreateLtoR() is obsoleted from version 1.1 on, and may disappear.
  520. This is because it it is only in the AES as "trial-use" and has been proposed
  521. for removal from the AES. Realistically, it will probably not be removed from
  522. any backward compatible versions of Motif, but the potential is there.  If it
  523. does disappear (or if you want to avoid using the non-AES compliant
  524. XmSTRING_DEFAULT_CHARSET), try this from Jean-Philippe Martin-Flatin
  525. <syj@ecmwf.co.uk>
  526.  
  527. #include <Xm/Xm.h>
  528. #include <string.h>
  529.  
  530. /*-----------------------------------------------------
  531.     Create a new XmString from a char*
  532.  
  533.     This function can deal with embedded 'newline' and
  534.     is equivalent to the obsolete XmStringCreateLtoR,
  535.     except it does not use non AES compliant charset
  536.     XmSTRING_DEFAULT_CHARSET
  537. ----------------------------------------------------*/
  538. XmString xec_NewString(char *s)
  539. {
  540.     XmString xms1;
  541.     XmString xms2;
  542.     XmString line;
  543.     XmString separator;
  544.     char     *p;
  545.     char     *t = XtNewString(s);   /* Make a copy for strtok not to */
  546.                                     /* damage the original string    */
  547.  
  548.  
  549.     separator = XmStringSeparatorCreate();
  550.     p         = strtok(t,"\n");
  551.     xms1      = XmStringCreateSimple(p);
  552.  
  553.     while (p = strtok(NULL,"\n"))
  554.     {
  555.         line = XmStringCreateSimple(p);
  556.         xms2 = XmStringConcat(xms1,separator);
  557.         XmStringFree(xms1);
  558.         xms1 = XmStringConcat(xms2,line);
  559.         XmStringFree(xms2);
  560.         XmStringFree(line);
  561.     }
  562.  
  563.     XmStringFree(separator);
  564.     XtFree(t);
  565.     return xms1;
  566. }
  567.  
  568.  
  569. Do not use XmStringCreateSimple() - it does not process the newline character
  570. in the way you want.
  571.  
  572. In UIL, you have to explicitly create a compound string with a separator.
  573. Here's what W. Scott Meeks suggests:
  574.  
  575. value nl : compound_string('', seperate=true);
  576.  
  577. object my_label : XmLabel
  578. {
  579.     arguments
  580.     {
  581.         XmNlabelString = 'Here' & nl & 'is' & nl & 'the' & nl & 'Label';
  582.     };
  583. };
  584.  
  585.  
  586. -----------------------------------------------------------------------------
  587. Subject: 67)  How can I have a vertical label?
  588.  
  589. Answer: Make a multiline label with one character per line, as in the last
  590. question. There is no way to make the text rotated by 90 degrees though.
  591.  
  592.  
  593. -----------------------------------------------------------------------------
  594. Subject: 68)  How can I have a Pixmap in a Label?
  595.  
  596. Answer: From Bob Hays (bobhays@spss.com)
  597.  
  598.     Pixmap px_disarm, px_disarm_insens;
  599.  
  600.     Widget Label1;
  601.     Pixel   foreground, background;
  602.     Arg     args[4];
  603.     Arg     arg[] = {
  604.                 { XmNforeground, &foreground },
  605.                 { XmNbackground, &background }
  606.     };
  607.  
  608.     Label1 = XmCreateLabel ( Shell1, "Label1",
  609.                                        (Arg *) NULL, (Cardinal) 0 );
  610.     XtGetValues ( Label1, arg, XtNumber ( arg ) );
  611.     px_disarm =
  612.       XCreatePixmapFromBitmapData(display,
  613.                                 DefaultRootWindow(display),
  614.                                 mtn_bits, mtn_width, mtn_height,
  615.                                 foreground,
  616.                                 background,
  617.                                 DefaultDepth(display,DefaultScreen(display)));
  618.     px_disarm_insens =
  619.       XCreatePixmapFromBitmapData(display,
  620.                                 DefaultRootWindow(display),
  621.                                 mtn_ins_bits, mtn_ins_width, mtn_ins_height,
  622.                                 foreground,
  623.                                 background,
  624.                                 DefaultDepth(display,DefaultScreen(display)));
  625.  
  626.     n = 0;
  627.     XtSetArg(args[n], XmNlabelType, XmPIXMAP);  n++;
  628.     XtSetArg(args[n], XmNlabelPixmap, px_disarm);  n++;
  629.     XtSetArg(args[n], XmNlabelInsensitivePixmap, px_disarm_insens ); n++;
  630.     XtSetValues ( Label1, args, n );
  631.     XtManageChild(Label1);
  632.  
  633. That will cause the foreground and background of your pixmap to be inherited
  634. from the one that would be used by OSF/Motif when the label is displayed.  The
  635. advantage is that this will utilize any resource values the user may have
  636. requested without looking explicitly into the resource database.  And, you
  637. will have a pixmap handy if the application insensitizes the label (without an
  638. XmNlabelInsensitivePixmap your label will go empty if made insensitive).
  639.  
  640. [Bob's original code was for a PushButton. Just change all Label to PushButton
  641. for them.]
  642.  
  643.  
  644. -----------------------------------------------------------------------------
  645. Subject: 69) TOPIC: DRAWING AREA WIDGET
  646.  
  647. -----------------------------------------------------------------------------
  648. Subject: 70) How can I send an expose event to a Drawing Area widget?  (or any
  649. other, come to that). I want to send an expose event so that it will redraw
  650. itself.
  651.  
  652. Answer: Use the Xlib call
  653.  
  654.         XClearArea(XtDisplay(w), XtWindow(w), 0, 0, 0, 0, True)
  655.  
  656. This clears the widget's window and generates an expose event in doing so.
  657. The widgets expose action will then redraw it.  This uses a round trip
  658. request.  An alternative, without the round trip is
  659.  
  660. from orca!mesa!rthomson@uunet.uu.net  (Rich Thomson):
  661.  
  662.     Widget da;
  663.     XmDrawingAreaCallbackStruct da_struct;
  664.  
  665.     da_struct.reason = XmCR_EXPOSE;
  666.     da_struct.event = (XEvent *) NULL;
  667.     da_struct.window = XtWindow(da);
  668.  
  669.     XtCallCallbacks(da, XmNexposeCallback, (XtPointer) da_struct);
  670.  
  671.  
  672. -----------------------------------------------------------------------------
  673. Subject: 71) How can I know when a DrawingArea has been resized?  It generates
  674. an expose event whn it is enlarged, but not when it is shrunk.
  675.  
  676. Answer: Use the resize callback.
  677.  
  678. -----------------------------------------------------------------------------
  679. Subject: 72) TOPIC: MENUS
  680.  
  681. -----------------------------------------------------------------------------
  682. Subject: 73) What can I put inside a menu bar?
  683.  
  684. Answer: You can only put cascade buttons in menu bars. No pushbuttons, toggle
  685. buttons or gadgets are allowed. When you create a pulldown menu with parent a
  686. menu bar, its real parent is a shell widget.
  687.  
  688. -----------------------------------------------------------------------------
  689. Subject: 74) Can I have a cascade button without a submenu in a pulldown menu?
  690.  
  691. Answer: Yes you can. A cascade button has an activate callback which is called
  692. when you click on it and it doesn't have a submenu. It can have a mnemonic,
  693. but keyboard traversal using the arrow keys in the menu will skip over it.
  694.  
  695. -----------------------------------------------------------------------------
  696. Subject: 75) Should I have a cascade button without a submenu in a pulldown
  697. menu?
  698.  
  699. Answer: No. This is forbidden by the style guide. Technically you can do it
  700. (see previous question) but if you do it will not be Motif style compliant.
  701. This is unlikely to change - if a "button" is important enough to be in a
  702. pulldown menu bar with no pulldown, it should be a button elsewhere.  (Mind
  703. you, you won't be able to put accelerators on it elsewhere though.)
  704.  
  705. -----------------------------------------------------------------------------
  706. Subject: 76)  What is the best way to create popup menus?
  707. [Last modified: August 92]
  708.  
  709. Susan Murdock Thompson (from OSF): In general, create a popupMenu as the child
  710. from which you will be posting it from (ie: if you have a bulletinBoard with a
  711. PushButton in it and want MB2 on the pushButton to post the popupMenu, create
  712. the popupMenu as a child of the pushButton).  [This parent-child relationship
  713. seems to make a big difference in the behavior of the popups.]  Add an event
  714. handler to handle buttonPress events.  You'll need to check for the correct
  715. button (what you've specified menuPost to be) before posting the menu.
  716.  
  717. To create a popup that can be accessible from within an entire client window,
  718. create it as the child of the top-most widget (but not the shell) and add
  719. event handlers for the top-most widget and children widgets.
  720.  
  721. ie:
  722.  
  723. {
  724.   ....
  725.  
  726.   XtManageChild(rc=XmCreateRowColumn(Shell1, "rc", NULL, 0));
  727.   XtManageChild(label = XmCreateLabel(rc, "label", NULL, 0));
  728.   XtManageChild(text = XmCreateText(rc, "text", NULL, 0));
  729.   XtManageChild(pushbutton = XmCreatePushButton(rc, "pushbutton", NULL, 0));
  730.  
  731.   n = 0;
  732.   XtSetArg(args[n], XmNmenuPost, "<Btn3Down>"); n++;
  733.   popup = XmCreatePopupMenu(rc, "popup", args, n);
  734.  
  735.   XtAddEventHandler(rc, ButtonPressMask, False, PostMenu3, popup);
  736.   XtAddEventHandler(text, ButtonPressMask, False, PostMenu3, popup);
  737.   XtAddEventHandler(label, ButtonPressMask, False, PostMenu3, popup);
  738.   XtAddEventHandler(pushbutton, ButtonPressMask, False, PostMenu3, popup);
  739.  
  740.   XtManageChild(m1 = XmCreatePushButton(popup, "m1", NULL, 0));
  741.   XtManageChild(m2 = XmCreatePushButton(popup, "m2", NULL, 0));
  742.   XtManageChild(m3 = XmCreatePushButton(popup, "m3", NULL, 0));
  743.  
  744.   XtAddCallback(m1, XmNactivateCallback, SayCB, "button M1");
  745.   XtAddCallback(m2, XmNactivateCallback, SayCB, "button M2");
  746.   XtAddCallback(m3, XmNactivateCallback, SayCB, "button M3");
  747.   ...
  748. }
  749.  
  750. /* where PostMenu3 is ... */
  751.  
  752. PostMenu3 (w, popup, event)
  753. Widget w;
  754. Widget popup;
  755. XButtonEvent * event;
  756. {
  757.   printf("menuPost = 3, button %d0, event->button);
  758.  
  759.   if (event->button != Button3)
  760.     return;
  761.   XmMenuPosition(popup, event);
  762.   XtManageChild(popup);
  763. }
  764.  
  765.  
  766.  
  767. -----------------------------------------------------------------------------
  768. Subject: 77)  How do popup menus work?
  769. [Last modified: August 92]
  770.  
  771. Answer:
  772.  
  773. When a popup menu is created as the child of a widget the menu system installs
  774. a translation on the parent of the popup and descendants with an action which:
  775. (1) when 3-rd button (the default for the menuPost resource) is pressed the
  776. cursor changes and the mouse is grabbed for 5 seconds; (2) disables event
  777. handlers on the descendants and the handlers are never called; (3) an event
  778. handler installed on the parent works fine.
  779.  
  780. It is done so that the correct event handler will (in fact) be called.  There
  781. is a grab with owner_events true.  The grab is released by a timer,  but
  782. normally the posted menu shell puts up it's own grab.
  783.  
  784. If you only have widgets then you can use the subwindow field in the event to
  785. identify the original widget.  If you have gadgets or other data that you want
  786. to change the menu for (or use a specific menu for) then you must do a walk of
  787. the parent's children to find the best match.
  788.  
  789. One thing to beware of is that even with the grab,  because the menu system
  790. does a grab with owner events true, you must either have an event handler, or
  791. nothing that will use the event on each widget in the hierarchy of the menu's
  792. parent.  If a child widget has another event handler for button down, it may
  793. swallow the event and do something else.
  794.  
  795.  
  796.  
  797. -----------------------------------------------------------------------------
  798. Subject: 78)  Should I use translation tables or actions for popup menus?
  799. [Last modified: August 92]
  800.  
  801. Answer: The original goal of popupMenus was that the user would not have to
  802. specify an event handler to manage popupMenus; however, that did not become
  803. reality.  Larry Rogers wrote:
  804.  
  805. > There appear to be two ways to manage popup menus.  I
  806. > am curious what the correct way would be:
  807.  
  808. > 1.  Change the translation table of the widget with the
  809. >    popup child to popup the menu.  Note that this does
  810. >    not currently working for many widgets, because aug-
  811. >    menting their translations, even for augment breaks
  812. >    the widget.
  813.  
  814. > 2.  Add an event handler at creation to the widget; then
  815. >    determine if the event that caused the event handler
  816. >    to be called is the current button being used by the
  817. >    menu as its activation button.
  818.  
  819. Susan Murdock Thompson (from OSF) replied: *Theoretically, you should be able
  820. to do both.*  Our documentation says use event handlers.  Our tests for the
  821. toolkit use event handlers and for UIL use translations.  (Although I tried an
  822. event handler with a UIL test and it works).
  823.  
  824. -----------------------------------------------------------------------------
  825. Subject: 79)  What are the known bugs in popup menus?
  826. [Last modified: August 92]
  827.  
  828. Answer: As at Motif 1.1.4, the bugs for which an OSF PIR exists are:
  829.  
  830.    (3)  Menus not being sticky (ie: posted on a Btn CLICK)  [ Note:this
  831.         problem occurs with OptionMenus as well]  (PIR 3435)
  832.  
  833.    (6)  Destroying a widget with an associated popupMenu results in
  834.         "Warning: Attempt to remove non-existant passive grab"         (PIR
  835. 2972)
  836.  
  837.    (7)  Current documentation insufficient regarding requirements for
  838.         success in using PopupMenus.  (PIR 3433)
  839.  
  840.  
  841. -----------------------------------------------------------------------------
  842. Subject: 80)  Can I have multiple popup menus on the same widget?
  843. [Last modified: August 92]
  844.  
  845. Answer: If you want to have several popups (activated by different mouse
  846. buttons) on the same widget..., well, that doesn't work yet.
  847.  
  848. If you want to have several popups on different children... that works.  But
  849. don't put a popup on the parent (manager) widget, or it will rule!
  850.  
  851.  
  852.  
  853. -----------------------------------------------------------------------------
  854. Subject: 81) TOPIC: INPUT FOCUS
  855.  
  856. -----------------------------------------------------------------------------
  857. Subject: 82) How can I direct the keyboard input to a particular widget?
  858.  
  859. Answer: In Motif 1.1 call XmProcessTraversal(target, XmTRAVERSE_CURRENT).  The
  860. widget (and all of its ancestors) does need to be realized BEFORE you call
  861. this. Otherwise it has no effect.  XmProcessTraversal is reported to have many
  862. bugs, so it may not work right.  A common occurrence is that it doesn't move
  863. to the widget, but if you call XmProcessTraversal *twice* in a row, it will.
  864. If you can't get it to work, try this from Kee Hinckley:
  865.  
  866.     // This insane sequence is as follows:
  867.     //      On manage set up a focus callback
  868.     //      On focus callback set up a timer (and get rid of focus callback!)
  869.     //      On timer set the focus (which only works if the parent
  870.     //      has the focus,
  871.     //      which is why we went through all of this garbage)
  872.     // There may be a better way, but I haven't time to try it now.
  873.     //
  874.     static void focusTO(void *data, XtIntervalId *) {
  875.         XmProcessTraversal((Widget) data, XmTRAVERSE_CURRENT);
  876.     }
  877.  
  878.     static void focusCB(Widget w, XtPointer data, XtPointer) {
  879.         XtRemoveCallback(w, XmNfocusCallback, focusCB, data);
  880.         XtAppAddTimeOut(XtWidgetToApplicationContext(w), 0, focusTO, data);
  881.     }
  882.  
  883.     void OmXSetFocus(Widget parent, Widget w) {
  884.         XtAddCallback(parent, XmNfocusCallback, focusCB, w);
  885.     }
  886.  
  887.  
  888. In Motif 1.0 call the undocumented _XmGrabTheFocus(target).
  889.  
  890. Do not use the X or Xt calls such as XtSetKeyboardFocus since this bypasses
  891. the Motif traversal layer and can cause it to get confused.  This can lead to
  892. odd keyboard behaviour elsewhere in your application.
  893.  
  894. -----------------------------------------------------------------------------
  895. Subject: 83)  How can I have a modal dialog which has to be answered before
  896. the application can continue?
  897. [Last modified: July 92]
  898.  
  899. Answer: The answer depends on whether you are using the Motif window manager
  900. mwm or not.  Test for this by XmIsMotifWMRunning.
  901.  
  902. The window manager mwm knows how to control event passing to dialog widgets
  903. declared as modal. If the dialog is set to application modal, then no
  904. interaction with the rest of the application can occur until the dialog is
  905. destroyed or unmanaged.
  906.  
  907. Use the appropriate code in the following program.  There is followup
  908. discussion after the program.
  909.  
  910.  
  911. /* Written by Dan Heller.  Copyright 1991, O'Reilly && Associates.
  912.  * This program is freely distributable without licensing fees and
  913.  * is provided without guarantee or warranty expressed or implied.
  914.  * This program is -not- in the public domain.  This program is
  915.  * taken from the Motif Programming Manual, O'Reilly Volume 6.
  916.  */
  917.  
  918. /*
  919.  * ask_user.c -- create a pushbutton that posts a dialog box
  920.  * that asks the user a question that requires an immediate
  921.  * response.  The function that asks the question actually
  922.  * posts the dialog that displays the question, waits for and
  923.  * returns the result.
  924.  */
  925. #include <X11/Intrinsic.h>
  926. #include <Xm/DialogS.h>
  927. #include <Xm/SelectioB.h>
  928. #include <Xm/RowColumn.h>
  929. #include <Xm/MessageB.h>
  930. #include <Xm/PushBG.h>
  931. #include <Xm/PushB.h>
  932.  
  933. XtAppContext app;
  934.  
  935. #define YES 1
  936. #define NO  2
  937.  
  938. /* main() --create a pushbutton whose callback pops up a dialog box */
  939. main(argc, argv)
  940. char *argv[];
  941. int argc;
  942. {
  943.     Widget parent, button, toplevel;
  944.     XmString label;
  945.     void pushed();
  946.  
  947.     toplevel = XtAppInitialize(&app, "Demos",
  948.         NULL, 0, &argc, argv, NULL, NULL, 0);
  949.  
  950.     label = XmStringCreateSimple("/bin/rm *");
  951.     button = XtVaCreateManagedWidget("button",
  952.         xmPushButtonWidgetClass, toplevel,
  953.         XmNlabelString,          label,
  954.         NULL);
  955.     XtAddCallback(button, XmNactivateCallback,
  956.         pushed, "Remove Everything?");
  957.     XmStringFree(label);
  958.  
  959.     XtRealizeWidget(toplevel);
  960.     XtAppMainLoop(app);
  961. }
  962.  
  963. /* pushed() --the callback routine for the main app's pushbutton. */
  964. void
  965. pushed(w, question)
  966. Widget w;
  967. char *question;
  968. {
  969.     if (AskUser(w, question) == YES)
  970.         puts("Yes");
  971.     else
  972.         puts("No");
  973. }
  974.  
  975. /*
  976.  * AskUser() -- a generalized routine that asks the user a question
  977.  * and returns the response.
  978.  */
  979. AskUser(parent, question)
  980. char *question;
  981. {
  982.     static Widget dialog;
  983.     XmString text, yes, no;
  984.     static int answer;
  985.     extern void response();
  986.  
  987.     answer = 0;
  988.     if (!dialog) {
  989.         dialog = XmCreateQuestionDialog(parent, "dialog", NULL, 0);
  990.         yes = XmStringCreateSimple("Yes");
  991.         no = XmStringCreateSimple("No");
  992.         XtVaSetValues(dialog,
  993.             XmNdialogStyle,        XmDIALOG_APPLICATION_MODAL,
  994.             XmNokLabelString,      yes,
  995.             XmNcancelLabelString,  no,
  996.             NULL);
  997.         XtSetSensitive(
  998.             XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON), False);
  999.         XtAddCallback(dialog, XmNokCallback, response, &answer);
  1000.         XtAddCallback(dialog, XmNcancelCallback, response, &answer);
  1001.         /* if the user interacts via the system menu: */
  1002.         XtAddCallback(dialog, XmNpopdownCallback, response, &answer);
  1003.     }
  1004.     text = XmStringCreateSimple(question);
  1005.     XtVaSetValues(dialog,
  1006.         XmNmessageString,      text,
  1007.         NULL);
  1008.     XmStringFree(text);
  1009.     XtManageChild(dialog);
  1010.     XtPopup(XtParent(dialog), XtGrabNone);
  1011.  
  1012.     /* while the user hasn't provided an answer, simulate XtMainLoop.
  1013.      * The answer changes as soon as the user selects one of the
  1014.      * buttons and the callback routine changes its value.  Don't
  1015.      * break loop until XtPending() also returns False to assure
  1016.      * widget destruction.
  1017.      */
  1018.     while (answer == 0 || XtAppPending(app))
  1019.         XtAppProcessEvent(app, XtIMAll);
  1020.     return answer;
  1021. }
  1022.  
  1023. /* response() --The user made some sort of response to the
  1024.  * question posed in AskUser().  Set the answer (client_data)
  1025.  * accordingly and destroy the dialog.
  1026.  */
  1027. void
  1028. response(w, answer, reason)
  1029. Widget w;
  1030. int *answer;
  1031. XmAnyCallbackStruct *reason;
  1032. {
  1033.     switch (reason->reason) {
  1034.         case XmCR_OK:
  1035.             *answer = YES;
  1036.             break;
  1037.         case XmCR_CANCEL:
  1038.             *answer = NO;
  1039.             break;
  1040.         default:
  1041.             *answer = NO;
  1042.             return;
  1043.     }
  1044. }
  1045.  
  1046.  
  1047.  
  1048. If you aren't running a window manager that acknowledges this hint, then you
  1049. may have to grab the pointer (and keyboard) yourself to make sure the user
  1050. doesn't interact with any other widget.  Change the grab flag in XtPopup to
  1051. XtGrabExclusive, and XtRemoveGrab(XtParent(w)) to the response() function.
  1052.  
  1053.  
  1054. -----------------------------------------------------------------------------
  1055. Subject: 84) TOPIC: MEMORY AND SPEED
  1056.  
  1057. -----------------------------------------------------------------------------
  1058. Subject: 85)  Why does my application grow in size?
  1059.  
  1060. Answer: Motif 1.0 has many memory leaks, particularly in XmString
  1061. manipulation.  Switch to Motif 1.1.
  1062.  
  1063. Answer: The Intrinsics have a memory leak in accelerator table management, and
  1064. Motif uses this heavily.  Avoid this by mapping/unmapping widgets rather than
  1065. creating/destroying them, or get  X11R4 fix-15/16/17.
  1066.  
  1067. Answer: The server may grow in size due to its own memory leaks.  Switch to a
  1068. later server.
  1069.  
  1070. Answer: You are responsible for garbage collection in `C'.  Some common cases
  1071. where a piece of memory becomes garbage are
  1072.  
  1073.  a.  Memory is allocated by Motif for XmStrings by the functions
  1074.      XmStringConcat, XmStringCopy, XmStringCreate, XmStringCreateLtoR,
  1075.      XmStringCreateSimple, XmStringDirectionCreate, XmStringNConcat,
  1076.      XmStringNCopy, XmStringSegmentCreate, and XmStringSeparatorCreate.  The
  1077.      values returned by these functions should be freed using XmStringFree
  1078.      when they are no longer needed.
  1079.  
  1080.  b.  Memory is allocated by Motif for ordinary character strings (of type
  1081.      String) by Motif in XmStringGetLtoR, XmStringGetNextComponent, and
  1082.      XmStringGetNextSegment. After using the string, XtFree() it. [Note that
  1083.      XmStrings and Strings are two different data types.  XmStrings are
  1084.      XmStringFree'd, Strings are XtFree'd.]
  1085.  
  1086.  c.  If you have set the label (an XmString) in a label, pushbutton, etc
  1087.      widget, free it after calling XtSetValues() or the widget creation
  1088.      routine by XmStringFree().
  1089.  
  1090.  d.  If you have set text in a text widget, the text widget makes its own
  1091.      copy.  Unless you have a use for it, there is no need to keep your own
  1092.      copy.
  1093.  
  1094.  e.  If you have set the strings in a list widget the list widget makes its
  1095.      own copy.  Unless you have a use for it, there is no need to keep your
  1096.      own copy.
  1097.  
  1098.  f.  When you get the value of a single compound string from a Widget e.g.
  1099.      XmNlabelString, XmNmessageString, ... Motif gives you a copy of its
  1100.      internal value.  You should XmStringFree this when you have finished with
  1101.      it.
  1102.  
  1103.  g.  On the other hand, when you get a value of a Table e.g. XmStringTable for
  1104.      a List, you get a *pointer* to the internal Table, and should not free
  1105.      it.
  1106.  
  1107.  h.  When you get the value of the text in a widget by XmTextGetString or from
  1108.      the resource XmNvalue, you get a copy of the text.  You should XtFree
  1109.      this when you have finished with it.
  1110.  
  1111. Answer: From Josef Nelissen: at least in Motif 1.1.4, X11R4 on a HP 720, the
  1112. XmText/XmTextFieldSetString() functions have a memory leak.  The old
  1113. value/contents of the Widget isn't freed correctly.  To work around this bug,
  1114. one should use a XmText Widget (in single-line-mode) instead of a XmTextField
  1115. Widget (the solution fails with XmTextField Widgets !) and replace any
  1116.  
  1117.        XmTextSetString(text_widget, str);
  1118.  
  1119. by
  1120.  
  1121.        XmTextReplace(text_widget, (XmTextPosition) 0,
  1122.                      XmTextGetLastPosition(text_widget), str);
  1123.  
  1124.  
  1125. -----------------------------------------------------------------------------
  1126. Subject: 86) Why does my application take a long time to start up?
  1127.  
  1128. Answer: You are probably creating too many widgets at startup time.  Delay
  1129. creating them until needed.  If you have a large number of resources in text
  1130. files (such as in app-defaults), time may be spent reading and parsing it.
  1131.  
  1132. -----------------------------------------------------------------------------
  1133. Subject: 87) My application is running too slowly. How can I speed it up?
  1134.  
  1135. Answer: Use the R4 rather than R3 server.  It is much faster.
  1136.  
  1137. Answer: The standard memory allocator is not well tuned to Motif, and can
  1138. degrade performance.  Use a better allocator.  e.g. with SCO Unix, link with
  1139. libmalloc.a; use the allocator from GNU emacs; use the allocator from Perl.
  1140.  
  1141. Answer: Avoid lots of widget creation and destruction.  It fragments memory
  1142. and slows everything down.  Popup/popdown, manage/unmanage instead.
  1143.  
  1144. Answer: Set mappedWhenManaged to FALSE, and then call XtMapWidget()
  1145. XtUnmapWidget() rather than managing.
  1146.  
  1147. Answer: Get more memory - your application, the server and the Operating
  1148. System may be spending a lot of time being swapped.
  1149.  
  1150. Answer: If you are doing much XmString work yourself, such as heavy use of
  1151. XmStringCompare, speed may deteriorate due to the large amount of internal
  1152. conversions and malloc'ing.  Try using XmStringByteCompare if appropriate or
  1153. ordinary Ascii strings if you can.
  1154.  
  1155.  
  1156.  
  1157. -----------------------------------------------------------------------------
  1158. END OF PART THREE
  1159. --
  1160. +----------------------+---+
  1161.   Jan Newmarch, Information Science and Engineering,
  1162.   University of Canberra, PO Box 1, Belconnen, Act 2616
  1163.   Australia. Tel: (Aust) 6-2012422. Fax: (Aust) 6-2015041
  1164.